﻿using MvvmFoundation.Wpf;
using QueryZJK.Common;
using QueryZJK.Helpers;
using QueryZJK.Models;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.Linq;
using System.Text;

namespace QueryZJK.ViewModels
{
    public sealed class MainViewModel : ObservableObject
    {
        public MainViewModel()
        {
            DJCGs = new DataTable();

            instantiateCommand();
        }

        private void instantiateCommand()
        {
            QueryCommand = new RelayCommand<Object>((obj) =>
            {
                QueryParameters param = new QueryParameters() { zh = ZH, djkid = FWBH, qxdm = QXDM };
                string sql = Regen_Base.GetMatchRegen(DJLX).GetSelectStr(param);
                var table = DbDaoManager.GetMatchDao().Select(sql);
                DJCGs = table;

            }, (obj) =>
            {
                return true;
            });
        }

        #region Props
        //证号zh
        private string zh = string.Empty;
        public string ZH
        {
            get
            {
                return zh;
            }
            set
            {
                if (zh == value)
                {
                    return;
                }

                zh = value;

                RaisePropertyChanged("ZH");
            }
        }

        //房屋编号fwbh
        private string fwbh = string.Empty;
        public string FWBH
        {
            get
            {
                return fwbh;
            }
            set
            {
                if (fwbh == value)
                {
                    return;
                }

                fwbh = value;

                RaisePropertyChanged("FWBH");
            }
        }

        //区县代码qxdm
        private QXDM qxdm = QXDM.NANMING;
        public QXDM QXDM
        {
            get
            {
                return qxdm;
            }
            set
            {
                if (qxdm == value)
                {
                    return;
                }

                qxdm = value;

                RaisePropertyChanged("QXDM");
            }
        }

        private DJLX djlx = default(DJLX);
        public DJLX DJLX
        {
            get
            {
                return djlx;
            }
            set
            {
                if (djlx == value)
                {
                    return;
                }

                djlx = value;

                RaisePropertyChanged("DJLX");
            }
        }

        private DataTable djcgs = null;
        public DataTable DJCGs
        {
            get
            {
                return djcgs;
            }
            set
            {
                if (djcgs == value)
                {
                    return;
                }

                djcgs = value;

                RaisePropertyChanged("DJCGs");
            }
        }
        #endregion

        #region Commands

        public RelayCommand<Object> QueryCommand { get; private set; }

        #endregion

        #region 枚举数据源
        public IEnumerable<ValueDescription> QXDMList
        { get { return EnumHelper.GetAllValuesAndDescriptions<QXDM>(); } }

        public IEnumerable<ValueDescription> DJLXList
        { get { return EnumHelper.GetAllValuesAndDescriptions<DJLX>(); } }
        #endregion
    }
}
